import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import CLIPSJNI.Environment;


/* Implement FindFact which returns just a FactAddressValue or null */
/* TBD Add size method to PrimitiveValue */

class HabilidadPanel extends JPanel {

    /**
     * 
     */
    private static final long serialVersionUID = -8179458997858426033L;

    JLabel dLabel;

    JComboBox racionalizacion  ;
    JComboBox trabajo_en_equipo  ;
    JComboBox liderazgo  ;
    JComboBox persuacion  ;
    JComboBox capacidad_comunicacion  ;

    
    JButton nextButton;
    JButton prevButton;
    JPanel choicesPanel;
    ButtonGroup choicesButtons;
	
	PrintWriter writer;

    Environment clips;

    public HabilidadPanel()  {

        /* ================================ */
        /* Create a new JFrame container. */
        /* ================================ */

        final JFrame jfrm = new JFrame("TestVocacionalDemo");

        /* ============================= */
        /* Specify FlowLayout manager. */
        /* ============================= */

        jfrm.getContentPane().setLayout(new GridLayout(1, 1));

        /* ================================= */
        /* Give the frame an initial size. */
        /* ================================= */

        jfrm.setSize(750, 300);
        jfrm.setLocation(200, 100);

        /* ============================================================= */
        /* Terminate the program when the user closes the application. */
        /* ============================================================= */

        jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        /* =========================== */
        /* Create the display panel. */
        /* =========================== */

        JPanel displayPanel = new JPanel();
        JLabel displayLabel = new JLabel();
        displayPanel.add(displayLabel);

        /* =========================== */
        /* Create the choices panel. */
        /* =========================== */
        choicesPanel = new JPanel();
        choicesPanel.setBorder(BorderFactory.createTitledBorder("Habilidades del alumno"));
       
        
        
        choicesPanel.setSize(400, 400);
        choicesPanel.setLayout(new BoxLayout(choicesPanel, BoxLayout.Y_AXIS));
        
        dLabel = new JLabel("Racionalizacion ");
        choicesPanel.add(dLabel);
        racionalizacion = new JComboBox();
        racionalizacion.addItem("alto");
        racionalizacion.addItem("medio");
        racionalizacion.addItem("bajo");
        choicesPanel.add(racionalizacion);

        dLabel = new JLabel("Trabajo en Equipo");
        choicesPanel.add(dLabel);
        trabajo_en_equipo = new JComboBox();
        trabajo_en_equipo.addItem("alto");
        trabajo_en_equipo.addItem("medio");
        trabajo_en_equipo.addItem("bajo");
        choicesPanel.add(trabajo_en_equipo);

        dLabel = new JLabel("Liderazgo");
        choicesPanel.add(dLabel);
        liderazgo = new JComboBox();
        liderazgo.addItem("alto");
        liderazgo.addItem("medio");
        liderazgo.addItem("bajo");
        choicesPanel.add(liderazgo);

        dLabel = new JLabel("Persuacion");
        choicesPanel.add(dLabel);
        persuacion  = new JComboBox();
        persuacion.addItem("alto");
        persuacion.addItem("medio");
        persuacion.addItem("bajo");
        choicesPanel.add(persuacion);

        dLabel = new JLabel("Capacidad Comunicacion");
        choicesPanel.add(dLabel);
        capacidad_comunicacion = new JComboBox();
        capacidad_comunicacion.addItem("alto");
        capacidad_comunicacion.addItem("medio");
        capacidad_comunicacion.addItem("bajo");
        choicesPanel.add(capacidad_comunicacion);

     
        /* =========================== */
        /* Create the buttons panel. */
        /* =========================== */

        
        try {
            writer = new PrintWriter("factsHabilidades.clp", "UTF-8");

        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        JPanel buttonPanel = new JPanel();


        nextButton = new JButton("Next");
        nextButton.setActionCommand("Next");
        choicesPanel.add(nextButton);
        nextButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                ResultadosEvaluacionAlumno resultadosEvaluacionAlumno = new ResultadosEvaluacionAlumno();
				
				writer.println("(deffacts caso_5 " );
				writer.println("	(habilidades " );
				writer.println("		(racionalizacion "+racionalizacion.getSelectedItem().toString()+")");
				writer.println("		(trabajo_en_equipo "+trabajo_en_equipo.getSelectedItem().toString()+")");
				writer.println("		(liderazgo "+liderazgo.getSelectedItem().toString()+")" );
				writer.println("		(persuacion "+persuacion.getSelectedItem().toString()+")");
				writer.println("		(capacidad_comunicacion "+capacidad_comunicacion.getSelectedItem().toString()+")))");
				writer.close();
				
				jfrm.setVisible(false);
                resultadosEvaluacionAlumno.setVisible(true);
				

            }
        });

        /* ===================================== */
        /* Add the panels to the content pane. */
        /* ===================================== */

        jfrm.getContentPane().add(displayPanel);
        jfrm.getContentPane().add(choicesPanel);
        jfrm.getContentPane().add(buttonPanel);

        /* ==================== */
        /* Display the frame. */
        /* ==================== */

        jfrm.setVisible(true);
        displayLabel.setText("Run clips file");
        /* ================================== */
        /* Get the current state of the UI. */
        /* ================================== */

    }


}
